using UnityEngine;

public class DailyBonusItem : MonoBehaviour
{
	public int indexInDailyBonus;

	public UISprite spriteBlack;

	public UISprite spriteTag;

	public UISprite spriteReward;

	public UITexture textureReward;

	public UILabel labelDay;

	public UILabel labelReward;

	private void OnDestroy()
	{
		textureReward.mainTexture = null;
	}

	private void Awake()
	{
		base.transform.localPosition = new Vector3(-290 + 70 * (indexInDailyBonus % 7), 66 - 64 * (indexInDailyBonus / 7));
		if (indexInDailyBonus % 7 == 0 || indexInDailyBonus % 7 == 3)
		{
			spriteReward.spriteName = "sprite_bounus_coin";
			spriteReward.MakePixelPerfect();
			labelReward.text = "x " + Global.dailyBonus[indexInDailyBonus / 7][indexInDailyBonus % 7];
		}
		else if (indexInDailyBonus % 7 == 1 || indexInDailyBonus % 7 == 5)
		{
			spriteReward.spriteName = "sprite_bounus_gem";
			spriteReward.MakePixelPerfect();
			labelReward.text = "x " + Global.dailyBonus[indexInDailyBonus / 7][indexInDailyBonus % 7];
		}
		else if (indexInDailyBonus % 7 == 2)
		{
			spriteReward.spriteName = "sprite_bounus_normal";
			spriteReward.SetDimensions(40, 40);
			labelReward.text = "x " + Global.dailyBonus[indexInDailyBonus / 7][indexInDailyBonus % 7];
		}
		else if (indexInDailyBonus % 7 == 6)
		{
			spriteReward.spriteName = "sprite_bounus_advance";
			spriteReward.SetDimensions(40, 40);
			labelReward.text = "x " + Global.dailyBonus[indexInDailyBonus / 7][indexInDailyBonus % 7];
		}
		else if (indexInDailyBonus % 7 == 4)
		{
			if (GameHelper.isCardTooMuch(GameData.CardsCount[GameHelper.getDailyBonusTeamIndex()] + Global.dailyBonus[indexInDailyBonus / 7][indexInDailyBonus % 7], GameHelper.getDailyBonusTeamIndex()))
			{
				spriteReward.spriteName = "sprite_bounus_coin";
				textureReward.mainTexture = null;
				labelReward.text = "x " + Global.dailyBonus[indexInDailyBonus / 7][indexInDailyBonus % 7] * Global.packageReward_normal[3];
				spriteReward.gameObject.SetActiveRecursively(state: true);
			}
			else
			{
				spriteReward.gameObject.SetActiveRecursively(state: false);
				textureReward.mainTexture = (Resources.Load("Logo/" + GameHelper.getDailyBonusTeamIndex(), typeof(Texture)) as Texture);
				labelReward.text = "x " + Global.dailyBonus[indexInDailyBonus / 7][indexInDailyBonus % 7];
			}
		}
		labelDay.text = string.Empty + (indexInDailyBonus + 1);
	}

	private void OnEnable()
	{
		if (GameData.CurrentDay > indexInDailyBonus)
		{
			spriteTag.gameObject.SetActiveRecursively(state: true);
			spriteBlack.gameObject.SetActiveRecursively(state: true);
		}
		else if (GameData.CurrentDay == indexInDailyBonus && GameData.IsGetCurrentDayBonus)
		{
			spriteTag.gameObject.SetActiveRecursively(state: true);
			spriteBlack.gameObject.SetActiveRecursively(state: true);
		}
		else
		{
			spriteTag.gameObject.SetActiveRecursively(state: false);
			spriteBlack.gameObject.SetActiveRecursively(state: false);
		}
		if (indexInDailyBonus % 7 == 4)
		{
			if (GameHelper.isCardTooMuch(GameData.CardsCount[GameHelper.getDailyBonusTeamIndex()] + Global.dailyBonus[indexInDailyBonus / 7][indexInDailyBonus % 7], GameHelper.getDailyBonusTeamIndex()))
			{
				spriteReward.spriteName = "sprite_bounus_coin";
				textureReward.mainTexture = null;
				labelReward.text = "x " + Global.dailyBonus[indexInDailyBonus / 7][indexInDailyBonus % 7] * Global.packageReward_normal[3];
				spriteReward.gameObject.SetActiveRecursively(state: true);
			}
			else
			{
				spriteReward.gameObject.SetActiveRecursively(state: false);
			}
		}
	}

	public void claim()
	{
		spriteBlack.gameObject.SetActiveRecursively(state: true);
		spriteTag.gameObject.SetActiveRecursively(state: true);
		TweenAlpha component = spriteTag.GetComponent<TweenAlpha>();
		component.enabled = true;
		component.from = 0f;
		component.to = 1f;
		component.duration = 0.3f;
		component.ResetToBeginning();
		component.PlayForward();
		TweenScale component2 = spriteTag.GetComponent<TweenScale>();
		component2.enabled = true;
		component2.from = Vector3.one * 1.5f;
		component2.to = Vector3.one;
		component2.duration = 0.3f;
		component2.ResetToBeginning();
		component2.PlayForward();
		Platform.flurryEventDailyBonus(indexInDailyBonus);
	}
}
